
import Vue from 'vue'
import Vuex from 'vuex'
// 导入封装好的存取数据
import { getItem, setItem, removeItem } from '@/utils/ls'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tokenInfo: getItem('token') || {}, // 判断是有否保存的token 没有则为空对象
    userInfo: {}
  },
  mutations: {
    // 保存TOKEN
    saveToken (state, newobj) {
      state.tokenInfo = newobj // 取出toke
      setItem('token', newobj) // 存入到浏览器
    },
    // 清除TOKEN
    clearToken (state) {
      state.tokenInfo = {}
      removeItem('token')
    },
    // 操作userInfo
    setUserInfo (state, info) {
      state.userInfo = info
    }
  },
  actions: {
  },
  modules: {
  }
})
